package com.itheima.jdbc.homework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @author ：石破天
 * @date ：Created in 2022年09月05日
 * @description ：
 * @version: 1.0
 */
public class InsertTest {

    public static void main(String[] args) throws Exception{
        //1:注册驱动 可以省略
        //2: 获取连接对象
        String url = "jdbc:mysql:///mydb?useSSL=false&useUnicode=true&characterEncoding=utf-8";
        String username="root";
        String password="root";
        Connection conn = DriverManager.getConnection(url, username, password);

        String name = "普信女";
        //3: 写sql
        String sql = "insert into student (name,age,birthday) values('"+name+"',28,'1995-01-01')";
        //4:  获取语句执行对象
        Statement state = conn.createStatement();
        //5:执行
        int i = state.executeUpdate(sql);
        //6 处理影响行数
        if(i>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }
        //7 释放资源
        state.close();
        conn.close();
    }
}
